/*
 * Copyright (C) 2011 TopCoder Inc., All Rights Reserved.
 */
package gov.nasa.pds.services;

import gov.nasa.pds.entities.DataFile;
import gov.nasa.pds.entities.DataSet;
import gov.nasa.pds.entities.Instrument;
import gov.nasa.pds.entities.InstrumentHost;
import gov.nasa.pds.entities.Mission;
import gov.nasa.pds.entities.Personnel;
import gov.nasa.pds.entities.Product;
import gov.nasa.pds.entities.Reference;
import gov.nasa.pds.entities.Table;
import gov.nasa.pds.entities.Target;
import gov.nasa.pds.entities.Volume;

/**
 * The persistence service used during the conversion process. Used to insert converted data.
 * 
 * Thread Safety: The implementations should be effectively thread-safe.
 */
public interface ConversionPersistence {
    /**
     * Creates the table structure based on the metadata found in the Table, including its columns.
     * 
     * @param table
     *            - the given table instance.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data.
     * 
     */
    void createTableStructure(Table table) throws DataSetProcessingException;

    /**
     * Inserts the given data into the given table into persistence.
     * 
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data.
     * 
     * @param table
     *            - the given table instance.
     */
    void insertDataIntoTable(Table table) throws DataSetProcessingException;

    /**
     * Inserts the given object into persistence.
     * 
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data
     * 
     * @param volume
     *            - the given volume instance.
     * @return - the id of volume.
     */
    long insertVolume(Volume volume) throws DataSetProcessingException;

    /**
     * Inserts the given object into persistence.
     * 
     * @param reference
     *            - the given reference instance.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data
     * @return - the id of reference.
     */
    long insertReference(Reference reference) throws DataSetProcessingException;

    /**
     * Inserts the given object into persistence.
     * 
     * @param instrumentHost
     *            - the given instrumentHost instance.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data
     * @return - the id of instrumentHost
     */
    long insertInstrumentHost(InstrumentHost instrumentHost) throws DataSetProcessingException;

    /**
     * Inserts the given object into persistence.
     * 
     * @param instrument
     *            - the given instrument instance.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data
     * @return - the id of instrument.
     */
    long insertInstrument(Instrument instrument) throws DataSetProcessingException;

    /**
     * Inserts the given object into persistence.
     * 
     * @param mission
     *            - the given mission instance.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data
     * @return - the id of mission
     */
    long insertMission(Mission mission) throws DataSetProcessingException;

    /**
     * Inserts the given object into persistence.
     * 
     * @param target
     *            - the given target instance.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data
     * @return - the id of target
     */
    long insertTarget(Target target) throws DataSetProcessingException;

    /**
     * 
     * @param personnel
     * @return
     * @throws DataSetProcessingException
     */
    public long insertPersonnel(Personnel personnel) throws DataSetProcessingException;
    
    /**
     * Inserts the given object into persistence.
     * 
     * @param dataSet
     *            - the given dataSet instance.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data
     * @return - the id of dataSet.
     */
    long insertDataSet(DataSet dataSet) throws DataSetProcessingException;

    /**
     * Inserts the given object into persistence.
     * 
     * @param product
     *            - the given product instance.
     * @param dataSetId
     *            - the given dataSetId value.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data.
     * @return - the id of product.
     */
    long insertProduct(long dataSetId, Product product) throws DataSetProcessingException;

    /**
     * Inserts the given object into persistence.
     * 
     * @param dataFile
     *            - the given dataFile instance.
     * @param productId
     *            - the given productId value.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data.
     * @return - the id of product.
     */
    long insertProductDocument(long productId, DataFile dataFile) throws DataSetProcessingException;

    /**
     * Inserts the given object into persistence.
     * 
     * @param dataSetId
     *            - the given dataSetId value.
     * @param dataFile
     *            - the given dataFile instance.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data.
     * @return - the id of dataFile
     */
    long insertDataSetDocument(long dataSetId, DataFile dataFile) throws DataSetProcessingException;

    /**
     * Associates the table with the given name to the product with the given ID.
     * 
     * @param productId
     *            - the given productId value.
     * @param dataTableName
     *            - the given dataTableName value.
     * @throws DataSetProcessingException
     *             - if there is an error while persisting the data.
     */
    void associateTableToProduct(long productId, String dataTableName) throws DataSetProcessingException;
}
